<?php
/**
 * Auto Complete on company
 *
 * @author Xavier VILAIN
 * 
 */

use Hive\Company;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Connection;

$term = utf8_decode(Xview::instance()->val('term'));

$term = Company::cleanup($term);
$terms = '%'.$term.'%';
$data = array();
$infos = Fox\Dao::infos(Company::className());
$query = $infos->handle()->createQueryBuilder();
$query->select('compid as id','company_name as label')
		->from($infos->tableName(),'t')
		->setMaxResults(10);
$fragment = new Fox\Dao\SqlFragment('company_keyname LIKE ? AND loekz = ?',array($terms,0));
$result = $fragment->pushIn($query)->execute()->fetchAll(PDO::FETCH_ASSOC);
echo Fox\Utilities::jsonUTF8Encode($result);